package com.itheima.homework.test9;

import java.util.HashMap;
import java.util.Set;

/*
现获取到一段文本，如下：
wo ai heima wo ai java wo yao hao hao xue xi java
单词间以空格分隔，请编写程序统计这段文本中每个单词出现的次数。输出格式如下：
xi(1)java(2)yao(1)hao(2)wo(3)ai(2)heima(1)xue(1)
 */
public class Demo9 {
    public static void main(String[] args) {
        HashMap<String,Integer> hs = new HashMap<>();
        String s ="wo ai heima wo ai java wo yao hao hao xue xi java";
        String[] ss = s.split(" ");

        for(int i = 0;i < ss.length;i++) {
            if (hs.containsKey(ss[i])) {
                int count = hs.get(ss[i]);
                hs.put(ss[i], ++count);
            } else {
                hs.put(ss[i], 1);
            }
        }
            //遍历
            Set<String> keys = hs.keySet();
            for (String key : keys) {
                System.out.print(key + "(" + hs.get(key) + ")");
            }


    }
}
